package com.common.loadbalance;

import com.common.loadbalance.impl.CircleLoadBalance;
import com.common.loadbalance.impl.IpHashLoadBalance;
import com.common.loadbalance.impl.RandomLoadBalance;


import java.util.List;

/**
 * @author Zixiang Hu
 * @description 定义通用的负载均衡接口
 * @create 2021-03-03-14:49
 */
public interface CommonLoadBalance {
    String getServerAddr(List<String> servers);

    static CommonLoadBalance getLoadBalanceByCode(int code){
        switch (code) {
            case 0:
                return new CircleLoadBalance();
            case 1:
                return new RandomLoadBalance();
            case 2:
                return new IpHashLoadBalance();
            default:
                return null;
        }
    }
}
